/*
 * * * Compile_AHK SETTINGS BEGIN * * *

[AHK2EXE]
Exe_File=%In_Dir%\Adventure 3g.exe
Alt_Bin=C:\Program Files\AutoHotkey\Compiler\AutoHotkeySC.bin
No_UPX=1
NoDecompile=1
Created_Date=1
[VERSION]
Set_Version_Info=1
Company_Name=Soggy Dog Productions
File_Description=Soggy Dog's Old-School Adventure
File_Version=2.8.11.7
Inc_File_Version=0
Internal_Name=Adventure.ahk
Legal_Copyright=copyright (c) 2011 Soggy Dog Productions
Original_Filename=Adventure.ahk
Product_Name=Soggy Dog's Old-School Adventure
Product_Version=1.0.48.5
Set_AHK_Version=1
[ICONS]
Icon_1=%In_Dir%\Adventure.ico
Icon_2=%In_Dir%\Adventure.ico
Icon_3=%In_Dir%\Adventure.ico
Icon_4=%In_Dir%\Adventure.ico
Icon_5=%In_Dir%\Adventure.ico
Icon_6=%In_Dir%\Adventure.ico
Icon_7=%In_Dir%\Adventure.ico

* * * Compile_AHK SETTINGS END * * *
*/

; ======================================================================================================
; Adventure
; ------------------------------------------------------------------------------------------------------
; Shannon D Gerton
; May 10, 2011
; ======================================================================================================
; July 17, 2011
;	! Corrected a layout issue (Room 3 West to wrong room)
; ------------------------------------------------------------------------------------------------------
; July 11, 2011
;	+ End Game added (Death)
;	+ Added *brief* room descriptions
; ------------------------------------------------------------------------------------------------------
; July 07, 2011
;	! Changed method for loading Castle array
;	! Corrected Room layout/labeling so that Entrance is called Room 1
; ------------------------------------------------------------------------------------------------------
; June 30, 2011
;	+ Added 7th Room (Exited - Outside - Win!)
;	! Modified Castle so that Room 2 is Entrance and Room 7 is Exit
;	+ Treasure added
;	+ Monsters added
;	+ End Game added (Win)
; ------------------------------------------------------------------------------------------------------
; May 29, 2011
; 	- Removed animated (and fake) "Initializing" message
;	+ Added genuine "Welcome" message
;	- Removed 7-room test array
; ------------------------------------------------------------------------------------------------------
; May 23, 2011
;	! Perfected navigational controls
; ------------------------------------------------------------------------------------------------------
; May 22, 2011
;	+ Added navigational controls
; ======================================================================================================



/*
	|-------------|-------------|
	|             |             |		     (1)
	|             |             |		      N
	|             -   ROOM 3    |		(4) W + E (2)
	|             -             |		      S
	|   ROOM 2    |             |		     (3)
	|             |-----| |-----| 
	| Stairs to 6 |             |		|-------------|
	|             |             |		|             |
	|             |             |		|             |		(5)
	|             |   ROOM 4    |		|             |		 U
	|-----| |-----|             |		|   ROOM 6    |		 |
	|             |             |		|             |		 D
	|             |             |		| Stairs to 2 |		(6)
	|             |-----| |-----|		|             |
	|   ROOM 1    |             |		|             |		(7) Contents
	|             |             |		|             |
	|             |   ROOM 5    |		|-------------|
	|             |             |
	|             |             |
	|-------------|-----| |-----|

	               EXIT - ROOM 7
*/



; ======================================================================================================
; == Title and Version
; ======================================================================================================
title = Soggy Dog's Old-School Adventure
version = v3.0g


; ======================================================================================================
; == Build GUI
; ======================================================================================================
; Needs Other #headers (like titleMatchMode, etc)
; Needs Icon(s) As Well
#singleInstance, force
#noTrayIcon

Gui, Add, GroupBox, x12 y10 w450 h180 , Message Center:
Gui, Add, edit, x22 y30 w430 h150 readOnly vMessageCenter
;				, `n`n`n`n`n`t`t`tWelcome to Adventure!`t`t`t`t`n
Gui, Add, GroupBox, x12 y195 w450 h50 , Player Command:
Gui, Add, Button, DEFAULT x402 y215 w50 h20 , Go
Gui, Add, edit, r1 vCommand x22 y215 w370 h30
Gui, Show, x120 y42 h257 w469, %title% %version%


; ======================================================================================================
; == Subroutine to Generate and Load Maps
; ======================================================================================================
gosub, Initialize


; ======================================================================================================
; == Main Loop
; ======================================================================================================
play:
turn := turn + 1
strength := strength - 5

if strength < 1
{
	goto, death
}

if strength < 15
{
	messageCenterMessage := % "Warning, " . playerName . "--  Your strength is low!||||"
	displayMessage(messageCenterMessage,standardDelay)
}

; Develop routine to actually get playerName
if strLen(playerName) = 0
	{
		playerName = Shannon
	}

if playerLocation = 7
{
	goto, win
}

messageCenterMessage := % "Turn " . turn . ":`n
	|You are in"
gosub, roomDescription

array = % "A_" . playerLocation . "_1"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "A door leads North.|"
	}

array = % "A_" . playerLocation . "_2"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "You can leave via the East exit.|"
	}

array = % "A_" . playerLocation . "_3"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "There is an exit to the South.|"
	}

array = % "A_" . playerLocation . "_4"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "A doorway opens to the West.|"
	}

array = % "A_" . playerLocation . "_5"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "There are stairs leading up.|"
	}

array = % "A_" . playerLocation . "_6"
if %array% <> 0
	{
	 messageCenterMessage := % messageCenterMessage . "A staircase decends to the floor below.|"
	}

messageCenterMessage := % messageCenterMessage . "|" . playerName . ", enter a Command or Direction.`n"
displayMessage(messageCenterMessage,standardDelay)
guicontrol,enabled,Command,
guicontrol,enabled,Go,
ControlFocus, Edit2, %title% %version%, Player Command:
return


; ======================================================================================================
; == Accept User Input
; ======================================================================================================
[enter]:
buttonGo:
Gui, Submit, NoHide
guicontrol,disabled,Command,
guicontrol,disabled,Go,

User_Input := subStr(command,1,1)
stringUpper,command, command

guicontrol,,command,

if (User_Input = "Q")	; Player Quitting?
	{
		messageCenterMessage := % "Turn " . turn . "(b):`n
		|Goodbye.
		|"
	displayMessage(messageCenterMessage,standardDelay)
	exitApp
	}

else

if inStr(commandList,User_Input) = 0	; Invalid Command
	{
	messageCenterMessage := % "Turn " . turn . "(b):`n
		|You can't " . command . " in this room.
		|||"
	displayMessage(messageCenterMessage,(standardDelay))
	goto play
	}
else
	messageCenterMessage := % "Turn " . turn . "(b):`n
		|"
	array = % "A_" . playerLocation . "_1"
	if user_Input = N
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "You can not move that way.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}

	array = % "A_" . playerLocation . "_2"
	if user_Input = E
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "You can't walk through walls.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}

	array = % "A_" . playerLocation . "_3"
	if user_Input = S
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "Try another direction.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}

	array = % "A_" . playerLocation . "_4"
	if user_Input = W
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "There is no door to the West.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}

	array = % "A_" . playerLocation . "_5"
	if user_Input = U
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "There is no way up from here.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}

	array = % "A_" . playerLocation . "_6"
	if user_Input = D
		{
		 if %array% = 0
			{
			 messageCenterMessage := % messageCenterMessage . "You can't go down from here.|||"
	 		 displayMessage(messageCenterMessage,standardDelay)
			 goto play
			}
		 else
			{
			 playerlocation := %array%
			 goto play
			}
		}
; Don't penalize player for bad input
turn := turn - 1
strength := strength + 5
goto play

death:
messageCenterMessage := % "Turn " . turn . ":`n
	|You are dead!!!
	||Your Score is " . 3*tally + 5*strength + 2*wealth + food + 30*mk . "."
displayMessage(messageCenterMessage,standardDelay)
goto, again

win:
messageCenterMessage := % "Turn " . turn . ":`n
	|You've done it!!
	|That was the exit to the Castle.
	|Well done, " . playerName . ".
	||Your Score is " . 3*tally + 5*strength + 2*wealth + food + 30*mk . "."
displayMessage(messageCenterMessage,standardDelay)
goto, again

again:
sleep, 10000
; "Play Again" routine here
exitApp

roomDescription:
if playerLocation = 1
{
	messageCenterMessage := % messageCenterMessage . " the entrance to the castle.|"
}
if playerLocation = 2
{
	messageCenterMessage := % messageCenterMessage . " a hallway.|"
}
if playerLocation = 3
{
	messageCenterMessage := % messageCenterMessage . " a storage area.|"
}
if playerLocation = 4
{
	messageCenterMessage := % messageCenterMessage . " the kitchen.|"
}
if playerLocation = 5
{
	messageCenterMessage := % messageCenterMessage . " the dining room.|"
}
if playerLocation = 6
{
	messageCenterMessage := % messageCenterMessage . " a bedroom.|"
}
return

; ======================================================================================================
; == Initialize
; ======================================================================================================
Initialize:
guicontrol,disabled,Command,
guicontrol,disabled,Go,
messageCenterMessage =
messageCenterMessage := % messageCenterMessage . "|Welcome to Soggy Dog's Old-School Adventure "
	. version
	. "|Concept by Atari Press, circa 1983"
	. "|Ported to AutoHotkey by Shannon D Gerton, 2011|||||"
displayMessage(messageCenterMessage,250)
sleep, 1000
; ======================================================================================================
; == Set Player Stats
; ======================================================================================================
turn = 0
command = 
commandList = NSEWUD
standardDelay = 333
strength = 100
wealth = 75
food = 0
tally = 0
mk = 0
sword = 0
amulet = 0
axe = 0
suit = 0
light = 0
; ======================================================================================================
; == Load Maps
; ======================================================================================================
rooms = 7
room1 = 2,0,0,0,0,0,0
room2 = 0,3,1,0,6,0,0
room3 = 0,0,4,2,0,0,0
room4 = 3,0,5,0,0,0,0
room5 = 4,0,7,0,0,0,0
room6 = 0,0,0,0,0,2,0
room7 = 0,0,0,0,0,0,0

Loop, %rooms%
{
room = %A_Index%
Loop,parse,room%room%,`,
	{
   		A_%room%_%A_Index% = %A_loopField%
	}
}
; ======================================================================================================
; == Hide Treasure
; ======================================================================================================
loop, 2
{
	treasure:
	random,j,1,%rooms%
	array = % "A_" . j . "_7"
	if (%array% <> 0 or j = 2 or j = 7)
	{
		goto treasure
	}
	random,%array%,10,109
}
; ======================================================================================================
; == Place Monsters
; ======================================================================================================
loop, 2
{
	monster:
	random,j,1,%rooms%
	array = % "A_" . j . "_7"
	if (%array% <> 0 or j = 2 or j = 7)
	{
		goto monster
	}
	%array% = -%j%
}
; ======================================================================================================
; == Place Static Treasure
; ======================================================================================================
; Original code calls for placing two additional Static Treasures,
; replacing anything else that may have already been placed there.
; This Proof-of-Concept Castle is too small for that at this time.
; I've assigned one Static Treasure to a non-existant room so that
; I don't forget to place them later in a larger Castle.
random,A_8_7,100,200
; ======================================================================================================
; == Set Player Information
; ======================================================================================================
playerName =		; Need routine to get Player Name
playerLocation = 1	; Start at Entrance of Castle
return


; ======================================================================================================
; == Exit Application
; ======================================================================================================
GuiClose:
ExitApp


; ======================================================================================================
; == Functions
; ======================================================================================================
displayMessage(message,delay)
{
	guicontrol,,MessageCenter,
	messageLine =
	StringSplit, messageArray, message, |
	Loop, %messageArray0%
	{	
   		messageLine := % messageLine . messageArray%a_index% . "`n"
		guicontrol,,MessageCenter, %messageLine%
		sleep, %delay%
	}
	return
}


; ======================================================================================================
; == Test Code
; ======================================================================================================
/*

	; ==================================================================================================
	; == Original "Rooms" Test - Doesn't run "Out-of-Context"
	; ==================================================================================================
	loop, 6 {					; -- Number of Rooms
		roomNumber = %A_Index%
		loop, 6 { 				; -- Number of Directions/Commands
			directionResults = %A_Index%	; -- N, E, S, W, U, D
			array = % "A_" . roomNumber . "_" . directionResults
			displayMessage(% "Room: " . roomNumber . "
				|" . "Direction: " . directionResults . "
				|" . "Result: " . %array%
			}
		}
	exitApp

	; ==================================================================================================
	; == Show Room Contents
	; ==================================================================================================
	msgbox, % A_1_7
		. " , " . A_2_7
		. " , " . A_3_7
		. " , " . A_4_7
		. " , " . A_5_7
		. " , " . A_6_7
		. " , " . A_7_7
		. " , " . A_8_7
	return

	; ==================================================================================================
	; == Show All Room Data
	; =================================================================================================
	msgbox, % "Room`tN`tE`tS`tW`tU`tD`tC`n"
		. "1`t" . A_1_1 . "`t" . A_1_2 . "`t" . A_1_3 . "`t" . A_1_4 
				. "`t" . A_1_5 . "`t" . A_1_6 . "`t" . A_1_7 . "`n"
		. "2`t" . A_2_1 . "`t" . A_2_2 . "`t" . A_2_3 . "`t" . A_2_4 
				. "`t" . A_2_5 . "`t" . A_2_6 . "`t" . A_2_7 . "`n"
		. "3`t" . A_3_1 . "`t" . A_3_2 . "`t" . A_3_3 . "`t" . A_3_4 
				. "`t" . A_3_5 . "`t" . A_3_6 . "`t" . A_3_7 . "`n"
		. "4`t" . A_4_1 . "`t" . A_4_2 . "`t" . A_4_3 . "`t" . A_4_4 
				. "`t" . A_4_5 . "`t" . A_4_6 . "`t" . A_4_7 . "`n"
		. "5`t" . A_5_1 . "`t" . A_5_2 . "`t" . A_5_3 . "`t" . A_5_4 
				. "`t" . A_5_5 . "`t" . A_5_6 . "`t" . A_5_7 . "`n"
		. "6`t" . A_6_1 . "`t" . A_6_2 . "`t" . A_6_3 . "`t" . A_6_4 
				. "`t" . A_6_5 . "`t" . A_6_6 . "`t" . A_6_7 . "`n"
		. "7`t" . A_7_1 . "`t" . A_7_2 . "`t" . A_7_3 . "`t" . A_7_4 
				. "`t" . A_7_5 . "`t" . A_7_6 . "`t" . A_7_7 . "`n"
	return

	; ==================================================================================================
	; == Random Room Number Generator
	; ==================================================================================================
	random:
	noRepeat = %playerLocation%
	random,playerLocation,1,%rooms%
	if playerLocation = %noRepeat%
		{
		goto random
		}
	else
		{
		return
		}
	return

	; ==================================================================================================
	; == Old Castle Definition
	; ==================================================================================================
	A_1_1 = 0 ;N
	A_1_2 = 3 ;E
	A_1_3 = 2 ;S
	A_1_4 = 0 ;W
	A_1_5 = 6 ;U
	A_1_6 = 0 ;D
	A_1_7 = 0 ;X
	A_2_1 = 1
	A_2_2 = 0
	A_2_3 = 0
	A_2_4 = 0
	A_2_5 = 0
	A_2_6 = 0
	A_2_7 = 0
	A_3_1 = 0
	A_3_2 = 0
	A_3_3 = 4
	A_3_4 = 1
	A_3_5 = 0
	A_3_6 = 0
	A_3_7 = 0
	A_4_1 = 3
	A_4_2 = 0
	A_4_3 = 5
	A_4_4 = 0
	A_4_5 = 0
	A_4_6 = 0
	A_4_7 = 0
	A_5_1 = 4
	A_5_2 = 0
	A_5_3 = 7
	A_5_4 = 0
	A_5_5 = 0
	A_5_6 = 0
	A_5_7 = 0
	A_6_1 = 0
	A_6_2 = 0
	A_6_3 = 0
	A_6_4 = 0
	A_6_5 = 0
	A_6_6 = 1
	A_6_7 = 0
	A_7_1 = 0
	A_7_2 = 0
	A_7_3 = 0
	A_7_4 = 0
	A_7_5 = 0
	A_7_6 = 0
	A_7_7 = 0

*/


; ======================================================================================================
; =============================================================================================  EOF  ==
; ======================================================================================================
